<template>
  <div>
    <Row>
      <Card>
        <p slot="title">
          <Icon type="navicon-round"></Icon>
          幼儿园管理
        </p>
        <VmBtable
          type="edit"
          ref="VmBtable"
          :columns="dataColumns"
          :data="dataTable"
          :searchparam="searchParam"
          :importBtn="false"
          :downTemplate="false"
          :exportBtn="false"
          :batchDelBtn="false"
          :isSearch="loginType !== 'kindergarten'"
          :isControl="loginType === 'platform'"
          :operate="operate"
          placeholder="幼儿园名称关键字"
          searchText="幼儿园名称："
          cleanText="刷新"
          @editFn="editFn"
          @delete="deleteFn"
          @configFn="configFn"
          v-on:searchFn="searchFn"
          v-on:page-change="pageChangeFn"
          v-on:addFn="addFn"
          v-on:restFn="restFn"
        >
          <div slot="search" class="db_inline"></div>
        </VmBtable>
      </Card>
    </Row>
    <Modal
      v-model="modal.visible"
      :title="modal.title"
      v-on:on-ok="subForm"
      :mask-closable="false"
      width="800"
      v-on:on-cancel="cancelSub"
    >
      <Row>
        <Col span="14">
          <Form
            ref="schoolForm"
            :model="modal.form"
            :label-width="80"
            label-position="right"
            :rules="modal.rules"
          >
            <FormItem label="名称" prop="name">
              <Input
                v-model="modal.form.name"
                placeholder="请输入幼儿园名称"
                style="width:90%"
              />
            </FormItem>
            <FormItem label="负责人" prop="chargePerson">
              <Input v-model="modal.form.chargePerson" placeholder="请输入负责人" style="width:90%"/>
            </FormItem>
            <FormItem label="联系号码" prop="phone">
              <Input v-model="modal.form.phone" placeholder="请输入联系号码" style="width:90%"/>
            </FormItem>
            <FormItem label="所属代理" prop="cliqueId" v-if="loginType!=='kindergarten'">
              <Select v-model="modal.form.cliqueId" label-in-value style="width:90%">
                <Option v-for="item in cliqueList" :value="item.id" :key="item.id">{{ item.name }}</Option>
              </Select>
            </FormItem>
            <FormItem label="角色分配" prop="brief" v-if="loginType!=='kindergarten'">
              <Select v-model="modal.form.brief" label-in-value style="width:90%">
                <Option v-for="item in ruleList" :value="item.name" :key="item.id">{{ item.name }}</Option>
              </Select>
            </FormItem>
            <FormItem class="db_inline" label="地址" v-if="!modal.isEdit" prop="countyId">
              <Select
                v-model="modal.form.provinceId"
                label-in-value
                @on-change="provinceChange"
                style="width:100px"
              >
                <Option
                  v-for="item in area.provinceList"
                  :value="item.id"
                  :key="item.id"
                >{{ item.name }}
                </Option>
              </Select>
              <Select
                v-model="modal.form.cityId"
                label-in-value
                @on-change="cityChange"
                style="width:100px"
              >
                <Option
                  v-for="item in area.cityList"
                  :value="item.id"
                  :key="item.id"
                >{{ item.name }}
                </Option>
              </Select>
              <Select
                v-model="modal.form.countyId"
                label-in-value
                @on-change="countyChange"
                style="width:120px"
              >
                <Option
                  v-for="item in area.countyList"
                  :value="item.id"
                  :key="item.id"
                >{{ item.name }}
                </Option>
              </Select>
            </FormItem>
            <FormItem label="详细地址" prop="detailAddress">
              <Input v-model="modal.form.detailAddress" placeholder="请输入详细地址" style="width:90%"/>
            </FormItem>
          </Form>
        </Col>
        <Col span="10">
          <Form>
            <FormItem label="幼儿园LOGO" prop="logo">
              <LogoUpload
                ref="logoUpload"
                accept="image/*"
                @get-file="getUploadFile"
                :multiple="false"
                delImgPath="kindergarten/logo"
              ></LogoUpload>
            </FormItem>
            <FormItem label="类型">
              <RadioGroup v-model="modal.form.type">
                <Radio :label=0>
                  <span>全托</span>
                </Radio>
                <Radio :label=1>
                  <span>半托</span>
                </Radio>
              </RadioGroup>
            </FormItem>
            <div v-if="loginType!=='kindergarten'">
              <FormItem label="以下增值服务">
                <RadioGroup v-model="modal.form.payConfig">
                  <Radio :label=0>
                    <span>免费使用</span>
                  </Radio>
                  <Radio :label=1>
                    <span>付费使用</span>
                  </Radio>
                </RadioGroup>
              </FormItem>
              <div>
                1、孩子出入园数据；
                2、孩子晨检体检报告消息推送
              </div>
              <FormItem style="margin-top: 20px" label="免费试用天数" v-if="modal.form.payConfig===1">
                <InputNumber :max="15" :min="1" v-model="modal.form.freeDay"></InputNumber>
                天
              </FormItem>
            </div>

          </Form>
        </Col>
      </Row>
      <div slot="footer">
        <Button type="text" @click="cancelSub">取消</Button>
        <Button type="primary" @click="subForm" :loading="modal.loading">确定</Button>
      </div>
    </Modal>
    <Modal
      v-model="wechat.visible"
      :title="wechat.title"
      v-on:on-ok="sureConfig"
      :mask-closable="false"
      width="680"
      v-on:on-cancel="cancelConfig"
    >
      <Form ref="wechatForm" :model="wechat.form" :label-width="120" :rules="wechat.rules">
        <Row>
          <Col span="12">
            <FormItem label="appId" prop="appId">
              <Input v-model="wechat.form.appId" placeholder="请输入微信appId" style="width:93%"/>
            </FormItem>
            <FormItem label="secret" prop="secret">
              <Input v-model="wechat.form.secret" placeholder="请输入微信secret" style="width:93%"/>
            </FormItem>
            <FormItem label="商户ID">
              <Input v-model="wechat.form.mchId" placeholder="请输入商户ID" style="width:93%"/>
            </FormItem>
            <FormItem label="商户秘钥">
              <Input v-model="wechat.form.apiKey" placeholder="请输入商户秘钥" style="width:93%"/>
            </FormItem>
            <FormItem label="域名" prop="domain">
              <Input v-model="wechat.form.domain" placeholder="请输入服务器域名" style="width:93%"/>
            </FormItem>
            <FormItem label="报告模板ID" prop="uhTemplateId">
              <Input v-model="wechat.form.uhTemplateId" placeholder="报告模板ID" style="width:93%"/>
            </FormItem>
            <FormItem label="请假模板ID" prop="leaveApplyTemplateId">
              <Input
                v-model="wechat.form.leaveApplyTemplateId"
                placeholder="请假模板ID"
                style="width:93%"
              />
            </FormItem>
          </Col>
          <Col span="12">
            <FormItem label="审核结果模板ID" prop="judeResultTemplateId">
              <Input
                v-model="wechat.form.judeResultTemplateId"
                placeholder="审核结果模板ID"
                style="width:93%"
              />
            </FormItem>
            <FormItem label="通知模板ID" prop="noticeTemplateId">
              <Input
                v-model="wechat.form.noticeTemplateId"
                placeholder="通知模板ID"
                style="width:93%"
              />
            </FormItem>
            <FormItem label="考勤统计模板ID" prop="staticsTemplateId">
              <Input
                v-model="wechat.form.staticsTemplateId"
                placeholder="考勤统计模板ID"
                style="width:93%"
              />
            </FormItem>
            <FormItem label="入校模板ID" prop="enterSchoolTemplateId">
              <Input
                v-model="wechat.form.enterSchoolTemplateId"
                placeholder="入校模板ID"
                style="width:93%"
              />
            </FormItem>
            <FormItem label="离校模板ID" prop="outSchoolTemplateId">
              <Input
                v-model="wechat.form.outSchoolTemplateId"
                placeholder="离校模板ID"
                style="width:93%"
              />
            </FormItem>
            <FormItem label="设备异常模板ID" prop="deviceWarningTemplateId">
              <Input
                v-model="wechat.form.deviceWarningTemplateId"
                placeholder="入校模板ID"
                style="width:93%"
              />
            </FormItem>
            <FormItem label="出入校模板ID" prop="inOrOutTemplateId">
              <Input
                v-model="wechat.form.inOrOutTemplateId"
                placeholder="出入校模板ID"
                style="width:93%"
              />
            </FormItem>
            <FormItem label="认证结果模板ID" prop="authResultTemplateId">
              <Input
                v-model="wechat.form.authResultTemplateId"
                placeholder="认证结果模板ID"
                style="width:93%"
              />
            </FormItem>
          </Col>
        </Row>
        <FormItem label="校验文件" v-if="wechat.showValidTxt" prop="validTxt">
          <Upload
            style="width:73%"
            accept=".txt"
            type="drag"
            :headers="headers"
            :data="{token:uploadToken}"
            :on-remove="removeValidTxt"
            :on-success="uploadSuccess"
            :action="action"
          >
            <div style="padding: 20px 0">
              <Icon type="ios-cloud-upload" size="52" style="color: #3399ff"></Icon>
              <p>选择校验文件</p>
            </div>
          </Upload>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="cancelConfig">取消</Button>
        <Button type="primary" @click="sureConfig" :loading="wechat.loading">确定</Button>
      </div>
    </Modal>
    <Modal
      v-model="account.visible"
      :title="account.title"
      v-on:on-ok="sureEdit"
      v-on:on-cancel="cancelEdit"
      :mask-closable="false"
      width="350"
    >
      <Form ref="accountForm" :model="account.form" :label-width="80" :rules="account.rules">
        <FormItem label="登录名" prop="adminAccount">
          <Input v-model="account.form.adminAccount" placeholder="请输入登录名" style="width:73%"/>
        </FormItem>
        <strong>注：</strong>账号只能修改一次！
      </Form>
      <div slot="footer">
        <Button type="text" @click="cancelEdit">取消</Button>
        <Button type="primary" @click="sureEdit" :loading="account.loading">确定</Button>
      </div>
    </Modal>
    <Modal v-model="qrcode.visible" title="注册二维码" width="450">
      <div style="text-align: center">
        <vue-qr v-if="qrcode.logoUrl" :logoSrc="qrcode.logoUrl" :logoScale="0.2" :text="qrcode.text"
                :size="400"></vue-qr>
        <vue-qr v-if="!qrcode.logoUrl" :text="qrcode.text" :size="400"></vue-qr>
      </div>
      <div slot="footer"></div>
    </Modal>
  </div>
</template>

<script>
import API from "@/api/api";
import VmBtable from "@/components/vm/vm-btable";
import LogoUpload from "@/components/views/upload/Upload";
import Cookie from "js-cookie";
import Axios from "axios";
import VueQr from 'vue-qr'

export default {
  components: {
    VmBtable,
    LogoUpload,
    VueQr
  },
  data() {
    const phoneValidate = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("请输入联系人电话"));
        // } else if (!/^1[3456789]\d{9}$/.test(value)) {
        //   callback("手机号码格式不正确");
      } else {
        callback();
      }
    };
    return {
      searchParam: {
        current: 1,
        size: 20,
        total: 0,
        name: ""
      },
      dataColumns: [
        {
          title: "序号",
          type: "index",
          align: "center",
          minWidth: 100
        },
        {
          title: "名称",
          align: "center",
          key: "name",
          minWidth: 200
        },
        {
          title: "编号",
          align: "center",
          key: "code",
          minWidth: 120
        },
        {
          title: "负责人",
          align: "center",
          key: "chargePerson",
          minWidth: 120
        },
        {
          title: "管理员账号",
          align: "center",
          key: "adminAccount",
          minWidth: 140,
          render: (h, param) => {
            return h(
              "div",
              {
                style: {
                  color: "blue",
                  cursor: "pointer"
                },
                on: {
                  click: () => {
                    this.editAdmin(param.row);
                  }
                }
              },
              param.row.adminAccount
            );
          }
        },
        {
          title: "联系号码",
          align: "center",
          key: "phone",
          minWidth: 160
        },
        {
          title: "所属代理",
          align: "center",
          key: "cliqueName",
          minWidth: 220
        },
        {
          title: "创建时间",
          align: "center",
          key: "createTime",
          minWidth: 180
        },
        {
          title: "创建人",
          align: "center",
          key: "createByName",
          minWidth: 120
        },
        {
          title: "操作",
          type: "operation",
          minWidth: 290,
          render: (h, param) => {
            let loginType = this.loginType;
            let operation = [];
            let edit = h(
              "Button",
              {
                props: {type: "info", size: "small"},
                style: {marginRight: "5px"},
                on: {
                  click: () => {
                    this.editFn(param.row);
                  }
                }
              },
              "编辑"
            );
            let resetpassword = h(
              "Button",
              {
                props: {type: "info", size: "small"},
                style: {marginRight: "5px"},
                on: {
                  click: () => {
                    this.resetpass(param.row);
                  }
                }
              },
              "重置密码"
            );
            let wechantConfig = h(
              "Button",
              {
                props: {type: "info", size: "small"},
                style: {marginRight: "5px"},
                on: {
                  click: () => {
                    this.configFn(param.row);
                  }
                }
              },
              "微信配置"
            );
            let registerBtn = h(
              "Button",
              {
                props: {type: "info", size: "small"},
                style: {marginRight: "5px"},
                on: {
                  click: () => {
                    this.showRegisterFn(param.row);
                  }
                }
              },
              "注册二维码"
            );
            let deleteFn = h(
              "Button",
              {
                props: {type: "error", size: "small"},
                style: {marginRight: "5px"},
                on: {
                  click: () => {
                    this.deleteFn(param.row);
                  }
                }
              },
              "删除"
            );
            let briefBtn = h(
              "Button",
              {
                props: {type: "info", size: "small"},
                style: {marginRight: "5px"},
                on: {
                  click: () => {
                    this.briefFn(param.row);
                  }
                }
              },
              "简介"
            );
            if (loginType === "kindergarten") {
              operation = [edit, registerBtn, briefBtn];
            } else if (
              loginType === "platform" ||
              loginType === "channel" ||
              loginType === "clique"
            ) {
              operation = [resetpassword, edit, registerBtn, wechantConfig, deleteFn];
            }
            return h("div", {}, operation);
          }
        }
      ],
      operate: [],
      dataTable: [],
      ruleList: [{id:1,name:'园区管理员'},{id:2,name:'园长'}],
      cliqueList: [],
      action: Axios.defaults.baseURL + "/cos/upload",
      headers: {
        Authorization: "Bearer " + Cookie.getJSON("TOKEN")
      },
      uploadToken: Cookie.getJSON("uploadToken"),
      loginType: Cookie.getJSON("loginType"),
      area: {
        provinceList: [],
        cityList: [],
        countyList: [],
        parentId: 0
      },
      modal: {
        visible: false,
        loading: false,
        isEdit: false,
        title: "",
        form: {
          brief: "",
          id: "",
          chargePerson: "",
          name: "",
          provinceId: "",
          provinceName: "",
          cityId: "",
          cityName: "",
          countyId: "",
          countyName: "",
          detailAddress: "",
          logo: "",
          cliqueId: "",
          payConfig: 0,
          freeDay: 5,
          type: 0
        },
        rules: {
          name: [
            {
              required: true,
              trigger: "blur",
              message: "必选项"
            }
          ],
          chargePerson: [
            {
              required: true,
              trigger: "blur",
              message: "必选项"
            }
          ],
          phone: [
            {
              required: true,
              validator: phoneValidate,
              trigger: "blur"
            }
          ],
          countyId: [
            {
              type: "number",
              required: true,
              trigger: "blur",
              message: "必选项"
            }
          ],
          cliqueId: [
            {
              type: "number",
              required: true,
              trigger: "blur",
              message: "必选项"
            }
          ],
          brief: [
            {
              required: true,
              trigger: "blur",
              message: "必选项"
            }
          ],
          detailAddress: [
            {
              required: true,
              trigger: "blur",
              message: "必选项"
            }
          ]
        }
      },
      wechat: {
        visible: false,
        title: "",
        loading: false,
        showValidTxt: true,
        form: {
          id: "",
          appId: "",
          secret: "",
          domain: "",
          merchantId: "",
          validTxt: "",
          mchId: "",
          apiKey: "",
          uhTemplateId: "",
          leaveApplyTemplateId: "",
          judeResultTemplateId: "",
          noticeTemplateId: "",
          staticsTemplateId: "",
          enterSchoolTemplateId: "",
          outSchoolTemplateId: "",
          deviceWarningTemplateId: "",
          inOrOutTemplateId: "",
          authResultTemplateId: "",
        },
        rules: {
          appId: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ],
          secret: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ],
          domain: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ],
          uhTemplateId: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ],
          leaveApplyTemplateId: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ],
          judeResultTemplateId: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ],
          noticeTemplateId: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ],
          staticsTemplateId: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ], enterSchoolTemplateId: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ], outSchoolTemplateId: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ], deviceWarningTemplateId: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ], inOrOutTemplateId: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ], authResultTemplateId: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ],
          validTxt: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ],
        }
      },
      account: {
        visible: false,
        title: "",
        loading: false,
        oldAccount: "",
        form: {
          adminAccount: ""
        },
        rules: {
          adminAccount: [
            {
              required: true,
              trigger: "blur",
              message: "必填项"
            }
          ]
        }
      },
      qrcode: {
        visible: false,
        logoUrl: '',
        text: ''
      }
    };
  },
  methods: {
    showRegisterFn(data) {
      let logoUrl = data.logoUrl;
      if (!logoUrl) {
        this.$Notice.warning({title: '警告', desc: '请先上传幼儿园logo'});
        return;
      }
      API.fetchRegisterCode({kindergartenId: data.id}).then(resp => {
        Object.assign(this.qrcode, {
          visible: true,
          logoUrl: data.logoUrl,
          text: resp.data
        })
      })
    },
    editAdmin(kindergarten) {
      if (kindergarten.editAccount) {
        this.$Message.warning("账号已更改过！");
        return;
      }
      this.account.oldAccount = kindergarten.adminAccount;
      Object.assign(this.account, {
        visible: true,
        title: "编辑【" + kindergarten.name + "】管理员"
      });
      Object.assign(this.account.form, kindergarten);
    },
    sureEdit() {
      this.$refs.accountForm.validate(valid => {
        if (valid) {
          if (this.account.oldAccount === this.account.form.adminAccount) {
            this.$Message.warning("新账号不能和原账号相同");
            return;
          }
          this.account.loading = true;
          API.updateAdminAccount(this.account.form)
            .then(resp => {
              this.queryFn();
              Object.assign(this.account, {
                visible: false,
                loading: false
              });
            })
            .catch(resp => {
              this.account.loading = false;
            });
        }
      });
    },
    cancelEdit() {
      Object.assign(this.account, {
        visible: false,
        loading: false
      });
    },
    getUploadFile(oldList, newFile) {
      this.modal.form.logo = newFile.name;
    },
    addFn() {
      Object.assign(this.modal, {
        visible: true,
        title: "添加幼儿园",
        isEdit: false,
        form: {payConfig: 0, freeDay: 5, type: 0}
      });
      this.$refs.logoUpload.acceptImageList([]);
    },
    resetpass(data) {
      var that = this
      this.$Modal.confirm({
        title: "警告",
        content: "是否重置学校密码为123456？",
        onOk: () => {
          this.$Spin.show({
            render: h => {
              return h("div", [
                h("Icon", {
                  class: "demo-spin-icon-load",
                  props: {
                    type: "load-c",
                    size: 18
                  }
                }),
                h("div", "重置中...")
              ]);
            }
          });
          API.kresetPwd(data.id).then(resp => {
            that.$Spin.hide();
            that.$Modal.confirm({
              title: "提示",
              content: "重置成功，新密码为123456",
              onOk: () => {
              }
            })

          })
        }
      });
    },
    editFn(data) {
      Object.assign(this.modal, {
        visible: true,
        title: "编辑【" + data.name + "】",
        isEdit: true,
      });
      Object.assign(this.modal.form, data);
      let logo = data.logo;
      if (!logo) {
        this.$refs.logoUpload.acceptImageList([]);
        return;
      }
      this.$refs.logoUpload.acceptImageList([
        {
          id: logo,
          key: logo,
          fname: logo,
          type: "pic"
        }
      ]);
    },
    briefFn(school) {
      this.$router.push({
        path: "/school-brief",
        query: {
          kId: school.id,
          n: school.name
        }
      });
    },
    deleteFn(data) {
      API.haveDevice({kindergartenId: data.id}).then(resp => {
        if (resp.msg == "成功") {
          this.$Modal.confirm({
            title: "警告",
            content: "是否删除该学校数据？",
            onOk: () => {
              this.$Spin.show({
                render: h => {
                  return h("div", [
                    h("Icon", {
                      class: "demo-spin-icon-load",
                      props: {
                        type: "load-c",
                        size: 18
                      }
                    }),
                    h("div", "删除中...")
                  ]);
                }
              });
              API.deleteKindergarten(data.id).then(resp => {
                this.queryFn();
                this.$Spin.hide();
              });
            }
          });
        } else {

        }
      })
    },
    configFn(data) {
      Object.assign(this.wechat, {
        visible: true,
        title: "配置【" + data.name + "】"
      });
      this.wechat.form.merchantId = data.id;
      API.fetchSchoolWechatConfig(data.id).then(resp => {
        if (resp.data) {
          this.wechat.showValidTxt = false;
          this.wechat.form = resp.data;
        } else {
          this.wechat.showValidTxt = true;
        }
      });
    },
    restFn() {
      this.searchParam.current = 1;
      this.searchParam.size = 20;
      this.searchParam.name = "";
      this.queryFn();
    },
    queryFn() {
      API.fetchKindergarten(this.searchParam).then(
        res => {
          let data = res.data;
          this.dataTable = data.records;
          this.searchParam.total = data.total;
        },
        error => {
          this.$Message.info(error.msg);
        }
      );
    },
    complete() {
      Object.assign(this.modal, {
        loading: false,
        visible: false
      });
      this.$refs.schoolForm.resetFields();
    },
    subForm() {
      this.$refs.schoolForm.validate(valid => {
        if (valid) {
          this.$Modal.confirm({
            title: "警告",
            content: "请确认手机号码是否正确，正确请按确认",
            onOk: () => {

              this.modal.loading = true;
              let data = Object.assign(this.modal.form);
              if (data.id) {
                API.updateKindergarten(data)
                  .then(resp => {
                    this.complete();
                    this.queryFn();
                  })
                  .catch(resp => {
                    this.modal.loading = false;
                  });
              } else {
                API.createKindergarten(data)
                  .then(resp => {
                    this.complete();
                    this.queryFn();
                  })
                  .catch(resp => {
                    this.modal.loading = false;
                  });
              }
            }
          });


        }
      });
    },
    cancelSub() {
      this.complete();
    },
    pageChangeFn(current) {
      this.searchParam.current = current;
      this.queryFn();
    },
    searchFn(value) {
      this.searchParam.name = value;
      this.queryFn();
    },
    fetchProvince() {
      API.fetchArea(0).then(resp => {
        this.area.provinceList = resp.data;
      });
    },
    fetchCity(provinceId) {
      API.fetchArea(provinceId).then(resp => {
        this.area.cityList = resp.data;
      });
    },
    fetchCounty(cityId) {
      API.fetchArea(cityId).then(resp => {
        this.area.countyList = resp.data;
      });
    },
    provinceChange(obj) {
      this.modal.form.cityId = "";
      this.modal.form.countyId = "";
      if (obj) {
        this.modal.form.provinceName = obj.label;
        this.fetchCity(obj.value);
      }
    },
    cityChange(obj) {
      this.modal.form.countyId = "";
      if (obj) {
        this.modal.form.cityName = obj.label;
        this.fetchCounty(obj.value);
      }
    },
    countyChange(obj) {
      if (obj) {
        this.modal.form.countyName = obj.label;
      }
    },
    sureConfig() {
      this.$refs.wechatForm.validate(valid => {
        if (valid) {
          this.wechat.loading = true;
          let data = Object.assign(this.wechat.form);
          API.setMerchantConfig(data).then(resp => {
            Object.assign(this.wechat, {
              loading: false,
              visible: false
            });
          });
        }
      });
    },
    cancelConfig() {
      Object.assign(this.wechat, {
        loading: false,
        visible: false
      });
      this.$refs.wechatForm.resetFields();
    },
    removeValidTxt(resp, fileList) {
      API.deleteFileFromQiNiu({fileName: resp.response.key}).then(resp => {
        this.wechat.form.validTxt = "";
      });
    },
    uploadSuccess(response, file, fileList) {
      this.wechat.form.validTxt = response.data.key;
    },
    fetchClique() {
      API.fetchClique().then(resp => {
        this.cliqueList = resp.data;
        if (this.cliqueList.length === 1) {
          this.modal.form.cliqueId = this.cliqueList[0].id;
        }
      });
    }
  },
  mounted() {
    this.queryFn();
    this.fetchProvince();
    if (this.loginType !== "kindergarten") {
      this.fetchClique();
    }
  }
};
</script>

<style scoped>
</style>
